<template>
  <div>
<van-picker
  title="标题"
  show-toolbar
  :columns="columns"
  :default-index="value"
  @confirm="onConfirm"
  @cancel="$emit('close')"
/>
  </div>
</template>

<script>
import { editUserinfo } from '@/api/user.js'
import { Toast } from 'vant'
export default {
  props: {
    value: {
      type: Number,
      require: true
    }
  },
  data () {
    return {
      columns: ['男', '女']
    }
  },

  created () {

  },

  methods: {
    async  onConfirm (val, index) {
      try {
        await editUserinfo({ gender: index })
        Toast.success('修改成功')
        this.$emit('close')
        this.$emit('input', index)
      } catch (err) {
        console.log(err)
        Toast.fail('修改失败')
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
